package com.bangyo.file;

import org.sothis.util.ObjectUtils;

import com.bangyo.core.entity.AbstractEntity;

public class UploadedFile extends AbstractEntity
{
    public UploadedFile()
    {
        super();
        setDescription("");
    }

    private String serverSideLocation = null;

    private String clientSideName = null;

    private String description = null;

    private long principalPartPoin = 0L;

    private MimeTypeName mimeTypeName = null;

    private Purpose purpose = null;

    private int score = 0;

    private int status = 0;

    private int options = 0;

    /**
     * 文件大小，字节为单位。
     */
    private long fileSize = 0L;

    /**
     * 将意图设为用户头像。
     */
    public void setPurposeAvatar()
    {
        setPurpose(Purpose.AVATAR);
    }

    /**
     * 判断意图是否为用户头像。
     * 
     * @return <code>true</code>，是；<code>false</code>，不是。
     */
    public boolean isPurposeAvatar()
    {
        return ObjectUtils.equal(Purpose.AVATAR, purpose);
    }

    /**
     * 将意图设为附件。
     */
    public void setPurposeAttachment()
    {
        setPurpose(Purpose.ATTACHMENT);
    }

    /**
     * 判断意图是否为附件。
     * 
     * @return <code>true</code>，是；<code>false</code>，不是。
     */
    public boolean isPurposeAttachment()
    {
        return ObjectUtils.equal(Purpose.ATTACHMENT, purpose);
    }

    /**
     * 设置MIME类型为image/jpeg。
     */
    public void setMimeTypeNameImageJpeg()
    {
        setMimeTypeName(MimeTypeName.JPEG);
    }

    /**
     * 判断MIME类型是否为image/jpeg。
     * 
     * @return <code>true</code>，是；<code>false</code>，不是。
     */
    public boolean isMimeTypeNameImageJpeg()
    {
        return ObjectUtils.equal(MimeTypeName.JPEG, mimeTypeName);
    }

    /**
     * 设置MIME类型为image/gif。
     */
    public void setMimeTypeNameImageGif()
    {
        setMimeTypeName(MimeTypeName.GIF);
    }

    /**
     * 判断MIME类型是否为image/gif。
     * 
     * @return <code>true</code>，是；<code>false</code>，不是。
     */
    public boolean isMimeTypeNameImageGif()
    {
        return ObjectUtils.equal(MimeTypeName.GIF, mimeTypeName);
    }

    /**
     * 设置MIME类型为image/png。
     */
    public void setMimeTypeNameImagePng()
    {
        setMimeTypeName(MimeTypeName.PNG);
    }

    /**
     * 判断MIME类型是否为image/png。
     * 
     * @return <code>true</code>，是；<code>false</code>，不是。
     */
    public boolean isMimeTypeNameImagePng()
    {
        return ObjectUtils.equal(MimeTypeName.PNG, mimeTypeName);
    }

    /**
     * 判断MIME类型是否为image。
     * 
     * @return <code>true</code>，是；<code>false</code>，不是。
     */
    public boolean isMimeTypeNameImage()
    {
        return startsWith("image/", mimeTypeName);
    }

    protected boolean startsWith(String text, Object prefix)
    {
        if (null==text||null==prefix)
        {
            return false;
        }

        return text.startsWith(prefix.toString());
    }

    public String getClientSideName()
    {
        return clientSideName;
    }

    public void setClientSideName(String clientSideName)
    {
        this.clientSideName = clientSideName;
    }

    protected long getPrincipalPartPoin()
    {
        return principalPartPoin;
    }

    protected void setPrincipalPartPoin(long principalPartPoin)
    {
        this.principalPartPoin = principalPartPoin;
    }

    public String getServerSideLocation()
    {
        return serverSideLocation;
    }

    public void setServerSideLocation(String serverSideLocation)
    {
        this.serverSideLocation = serverSideLocation;
    }

    public MimeTypeName getMimeTypeName()
    {
        return mimeTypeName;
    }

    public void setMimeTypeName(MimeTypeName type)
    {
        this.mimeTypeName = type;
    }

    public long getFileSize()
    {
        return fileSize;
    }

    public void setFileSize(long fileSize)
    {
        this.fileSize = fileSize;
    }

    protected Purpose getPurpose()
    {
        return purpose;
    }

    protected void setPurpose(Purpose purpose)
    {
        this.purpose = purpose;
    }

    public String getDescription()
    {
        return description;
    }

    public void setDescription(String description)
    {
        this.description = description;
    }

    public int getScore()
    {
        return score;
    }

    public void setScore(int score)
    {
        this.score = score;
    }

    public int getStatus()
    {
        return status;
    }

    public void setStatus(int status)
    {
        this.status = status;
    }

    public int getOptions()
    {
        return options;
    }

    public void setOptions(int options)
    {
        this.options = options;
    }

    private static final long serialVersionUID = 6864951137157027917L;
}